<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item" :style="importantStyle">
                <svg-icon icon-class="lock" /><span class="info-label">登录账号</span>
                <div class="pull-right">{{ user.username }}</div>
              </li>
              <li class="list-group-item" :style="importantStyle">
                <svg-icon icon-class="user" /><span class="info-label">真实姓名</span>
                <div class="pull-right">{{ user.realname }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tag" /><span class="info-label">昵称</span>
                <div class="pull-right">{{ user.nickName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="man" v-if="user.sex==1"/>
                <svg-icon icon-class="woman" v-else/>
                <span class="info-label">性别</span>
                <div class="pull-right">{{ user.sexDictText }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" /><span class="info-label">手机号</span>
                <div class="pull-right">{{ user.phone }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="mail" /><span class="info-label">邮箱</span>
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item" :style="importantStyle">
                <svg-icon icon-class="team" /><span class="info-label">角色</span>
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item" :style="importantStyle">
                <svg-icon icon-class="apartment" />组织机构
                <div class="pull-right" >{{ user.deptName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="idcard" />职位
                <div class="pull-right" >{{ user.postDictText }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="calendar-check" /><span class="info-label">创建日期</span>
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="login" /><span class="info-label">登录时间</span>
                <div class="pull-right">{{ user.loginTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <userInfo :user="userBase" @ok="getUser()"/>
        </el-card>
      </el-col>
    </el-row>


  </div>
</template>

<style scoped>
  .list-group-item .svg-icon{
      margin-right: 6px;
  }
</style>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import updatePwd from "./updatePwd";
import { getUserInfo } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, updatePwd },
  data() {
    return {
      userBase: {},
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo"
    };
  },
  created() {
    this.getUser();
  },
  computed:{
    importantStyle(){
      return {
        color: this.$store.state.settings.theme,
        'fontWeight': 'bold'
      }
    }
  },
  methods: {
    getUser() {
      getUserInfo().then(res => {
        this.user = res.data.user;
        let {nickName, phone, email, sex} = res.data.user
        this.userBase = {nickName, phone, email, sex};
        this.roleGroup = res.data.roleGroup;
        this.postGroup = res.data.postGroup;
      });
    }
  }
};
</script>
